# coding:utf-8

from marshmallow import fields, validate

from app.api.utils import EmptyStrValidator
from app.api_v2.constant import MOBILE_FORMAT
from ..extensions import ma


class AppMobileSchema(ma.Schema):
    """
    create by ld_wu 2017-11-20
    """
    mobile = fields.Str(
        required=True,
        error_messages={'required': '手机号为必填'},
        validate=[
            EmptyStrValidator(error='手机号不能为空'),
            validate.Regexp(MOBILE_FORMAT, error='请输入正确的手机号')
        ]
    )


class AppLoginSchema(AppMobileSchema):
    """
    create by ld_wu 2017-11-20
    """

    sms_captcha = fields.Str(
        required=True,
        error_messages={'required': '短信验证码为必填'},
        validate=EmptyStrValidator(error='短信验证码不合法')
    )
    app_invite_user_id = fields.Int()
    registration_id = fields.String()
    app_login_version = fields.Str()

app_login_schema = AppLoginSchema()
app_mobile_schema = AppMobileSchema()
